package com.fanxuankai.ksql.function.udf.datetime;

import io.confluent.ksql.function.udf.Udf;
import io.confluent.ksql.function.udf.UdfDescription;
import io.confluent.ksql.function.udf.UdfParameter;

import java.sql.Date;
import java.sql.Time;
import java.sql.Timestamp;

/**
 * @author fanxuankai
 */
@UdfDescription(name = "get_second", description = "秒", author = "fanxuankai")
public class Second {
    @Udf
    public Integer calc(@UdfParameter("val") Timestamp o) {
        return o == null ? null : o.toLocalDateTime().getSecond();
    }

    @Udf
    public Integer calc(@UdfParameter("val") Date o) {
        return o == null ? null : calc(new Time(o.getTime()));
    }

    @Udf
    public Integer calc(@UdfParameter("val") Time o) {
        return o == null ? null : o.toLocalTime().getSecond();
    }
}
